package com.base.myproject.client.HR.bcode;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseTabPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;

public class Bcode_EmployeeChange extends LayoutContainer implements LasyObejct {
	Button save = new Button("保存");
	Button bt1 = new Button("转正");
	Button bt2 = new Button("撤消转正");
	Button bt3 = new Button("再入职");
	CheckBox checkBox1 = new CheckBox();// 延续工作年限
	// 部门
	BaseComboBoxForm<BaseModelData> C_dep;
	BaseComboBoxForm<BaseModelData> C_deppraent;
	BaseComboBoxForm<BaseModelData> dep;
	TextField<String> C_num25;// 识别码
	// 职级
	BaseComboBoxX C_employlevel = new BaseComboBoxX("name", "dictionary",
			"where type='zy'");
	TextField<String> employlevel;
	// 职位
	BaseComboBoxX C_employoutertitle = new BaseComboBoxX("job_name",
			"job_table", "where type='hr_title'");
	TextField<String> employoutertitle;
	// 状态
	BaseComboBoxX C_employstatus = new BaseComboBoxX("name", "dictionary",
			"where type='zyzk'");
	TextField<String> employstatus;
	// 组别
	BaseComboBoxX C_jobgroup = new BaseComboBoxX("name", "dictionary",
			"where type='hr_jobgroup'");
	TextField<String> jobgroup;
	// 薪金
	NumberField salary = new NumberField();
	NumberField salary1;

	// 变动原因
	BaseComboBoxX C_employeechangeremark = new BaseComboBoxX("name",
			"dictionary", "where type='employeechange'");
	DateField changeDate;
	BaseStore<BusiObject> mainstore = null;

	Button dimission = new Button("离职");
	Button entry = new Button("入职");
	Button resume = new Button("撤消离职");
	Button print = new Button("打印离职清点");
	TabPanel tabpanel = new TabPanel();

	ArrayList<BaseStore<BusiObject>> refresh_list = new ArrayList<BaseStore<BusiObject>>();

	Date df_date;
	private Button btnLeaveInquiry;
	BcodeMain main;//大管家
	
	boolean isEntry = false;

	public Bcode_EmployeeChange(BcodeMain main) {
		this.main = main;
		this.mainstore = main.getStore();
		init();
	}

	public Bcode_EmployeeChange() {

	}

	private void init() {
		Func = new EmployChange_func(mainstore, this);
		
		String getDate = "select getdate() as date";
		final GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService.getDataSet(getDate, new AsyncCallback<DataSet>() {
			@Override
			public void onFailure(Throwable caught) {
			}

			@Override
			public void onSuccess(DataSet result) {
				getGroupStore().removeAll();
				if (result.getRowCount() > 0) {
					DateTimeFormat format = DateTimeFormat
					.getFormat("yyyy-MM-dd HH:mm:ss");
					String date = result.getValue(0, "date");
					df_date = format.parse(date);
					
					changeDate.setValue(df_date);
					changeDate.setPropertyEditor(new DateTimePropertyEditor("yyyy-MM-dd"));
					changeDate.setFormatValue(false);
				}
			}
		});

		tabpanel.setPlain(true);
		tabpanel.setAutoHeight(true);
		tabpanel.setWidth(755);

		VerticalPanel vp = new VerticalPanel();
		vp.setSpacing(3);
		vp.add(getGroupGrid());
		vp.add(initWidget());

		TabItem t1 = new TabItem();
		t1.setText("本司工作经历");
		t1.add(vp);
		t1.setScrollMode(Scroll.AUTO);

		VerticalPanel v = new VerticalPanel();
		v.setSpacing(2);

		TabItem t2 = new TabItem();
		t2.setText("早前工作经历");
		t2.add(create_job_his_a_Grid());
		t2.setScrollMode(Scroll.AUTO);

		tabpanel.add(t1);
		tabpanel.add(t2);

		v.add(tabpanel);
		this.add(v);

//		df_date.setYear(currentTime.getYear());
//		df_date.setMonth(currentTime.getMonth());
//		df_date.setDate(currentTime.getDate());
		

	}

	/***********************************************/

	BaseStore<BusiObject> store = null;

	BaseStore<BusiObject> createStore_ZZ() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");

		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("whether_continue");
		type.getField("whether_continue").setType(Boolean.class);
		type.addField("Notes");
		type.getField("Notes").setType(String.class);

		StoreInfo info = new StoreInfo();
		info.setTablename("hr_EmployeeChange");
		info.setKeyname(new String[] { "icode" });
		info
				.setSql("select * from hr_EmployeeChange where bcode='{bcode}' and changetype='转正' and icode=(select top 1 icode from hr_EmployeeChange  order by changedate desc)");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		store = new BaseStore<BusiObject>(type, info);
		return store;
	}

	BaseStore<BusiObject> store2 = null;

	BaseStore<BusiObject> getStore2() {
		if (store2 == null) {
			createStore2();
		}
		return store2;
	}

	BaseStore<BusiObject> createStore2() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");

		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("employno");
		type.getField("employno").setType(String.class);
		type.addField("employlevel");
		type.getField("employlevel").setType(String.class);
		type.addField("employinnertitle");
		type.getField("employinnertitle").setType(String.class);
		type.addField("employstatus");
		type.getField("employstatus").setType(String.class);
		type.addField("jobgroup");
		type.getField("jobgroup").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_job");
		info.setKeyname(new String[] { "icode" });
		info
				.setSql("select icode,bcode,employlevel,employno,employinnertitle,employstatus,jobgroup from bcode_job where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		store2 = new BaseStore<BusiObject>(type, info);
		return store2;
	}

	BaseStore<BusiObject> store3 = null;

	BaseStore<BusiObject> getStore3() {
		if (store3 == null) {
			createStore3();
		}
		return store3;
	}

	BaseStore<BusiObject> createStore3() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");

		type.addField("entrydate");
		type.getField("entrydate").setType(Date.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_job");
		info.setKeyname(new String[] { "icode" });
		info
				.setSql("select DateAdd(Month,3,entrydate) as entrydate from bcode_job where jobtype='试用工' and  bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });// 关联主表字段
		store3 = new BaseStore<BusiObject>(type, info);
		return store3;
	}

	GroupingStore<BusiObject> groupStore = null;

	GroupingStore<BusiObject> getGroupStore() {
		if (groupStore == null) {
			createGroupStore();
		}
		return groupStore;
	}

	GroupingStore<BusiObject> createGroupStore() {
		groupStore = new GroupingStore<BusiObject>();
		groupStore.groupBy("ChangeDate");
		getEmployeeChange(Env.getEnvbcode(), Env.getEnvname());
		return groupStore;
	}

	String bname = null;
	String bcode = null;

	void getEmployeeChange(String bcode, final String bcodeName) {
		this.bcode = bcode;
		
		String sql = "select * from hr_EmployeeChange where bcode = '" + bcode
				+ "'";
		final GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService.getDataSet(sql, new AsyncCallback<DataSet>() {
			@Override
			public void onFailure(Throwable caught) {
			}

			@Override
			public void onSuccess(DataSet result) {
				getGroupStore().removeAll();
				if (result.getRowCount() > 0) {
					bname = bcodeName;
					BusiObject bo = null;
					List<BusiObject> list = new ArrayList<BusiObject>();
					for (int i = 0; i < result.getRowCount(); i++) {
						bo = new BusiObject();
						bo.set("ChangeType", result.getValue(i, "ChangeType"));
						bo.set("ChangeDate", result.getValue(i,
								"ChangeDate"));
						bo.set("before", result.getValue(i, "before"));
						bo.set("after", result.getValue(i, "after"));
						bo.set("remark", result.getValue(i, "remark"));
						bo.set("Notes", result.getValue(i, "Notes"));
						list.add(bo);
					}
					getGroupStore().add(list);
					grid.getView().refresh(true);
				}
			}
		});
	}

	ColumnModel cm;
	Grid<BusiObject> grid = null;

	private Grid<BusiObject> getGroupGrid() {
		try {
			List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
			ColumnConfig changetype = new ColumnConfig("ChangeType", "变动类型",
					100);
			ColumnConfig availabledate = new ColumnConfig("ChangeDate",
					"生效日期", 100);
			availabledate.setDateTimeFormat(DateTimeFormat
					.getFormat("yyyy-MM-dd"));

			ColumnConfig before = new ColumnConfig("before", "变动前", 100);
			ColumnConfig after = new ColumnConfig("after", "变动后", 100);
			ColumnConfig Notes = new ColumnConfig("Notes", "备注", 200);

			columns.add(changetype);
			columns.add(availabledate);
			columns.add(before);
			columns.add(after);
			columns.add(Notes);

			cm = new ColumnModel(columns);

			GroupingView view = new GroupingView();
			view.setShowGroupedColumn(false);
			view.setForceFit(true);
			view.setGroupRenderer(new GridGroupRenderer() {
				public String render(GroupColumnData data) {
					String remark = data.models.get(0).get("remark");
					return data.group.substring(0, 10) + "：" + bname
							+ "由于[" + remark + "],变动如下：";
				}
			});

			grid = new Grid<BusiObject>(getGroupStore(), cm);
			grid.setSize(745, 200);
			grid.setView(view);
			grid.setBorders(true);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		return grid;
	}

	private TextField<String> tfRemark = null;
	FormPanel form;
	BaseFormPanel form1;
	BaseFormPanel form2;
	BaseFormPanel form3;
	BaseFormPanel form4;
	
	BaseComboBoxX bcLeaveReason = new BaseComboBoxX("name", "dictionary",
	"where type = 'hr_leavereason'");
	
	public VerticalPanel initWidget() {
		VerticalPanel v = new VerticalPanel();

		TableLayout tl = new TableLayout(4);
		TableData td1 = new TableData();
		td1.setHorizontalAlign(HorizontalAlignment.LEFT);
		td1.setVerticalAlign(VerticalAlignment.MIDDLE);
		td1.setColspan(1);
		td1.setPadding(1);

		TableLayout t3 = new TableLayout(6);
		form = new FormPanel();
		form.setHeaderVisible(false);
		form.setBodyBorder(false);
		form.setPadding(2);
		form.setLayout(t3);

		form.add(new Label("生效日期:"), td1);
		changeDate = new DateField();
		changeDate.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-MM-dd"));
		form.add(changeDate, td1);
		changeDate.setWidth(127);
		changeDate.setAllowBlank(false);

		C_employeechangeremark.setWidth(127);
		C_employeechangeremark.setAllowBlank(false);
		form.add(new Label("变动原因:"), td1);
		form.add(C_employeechangeremark, td1);

		form.add(new Label("备注:"), td1);
		tfRemark = new TextField<String>();
		tfRemark.setWidth(323);
		form.add(tfRemark, td1);
		form.setBodyBorder(false);

		form1 = new BaseFormPanel(mainstore, false);
		form1.setHeaderVisible(false);
		form1.setBodyBorder(false);
		form1.setLayout(tl);
		form1.setPadding(2);

		form1.add(new Label("薪金由"), td1);
		salary1 = new NumberField();
		salary1.setEnabled(false);
		salary1.setWidth(133);
		salary1.setName("basesalary");
		form1.add(salary1, td1);
		form1.add(new Label("改变为"), td1);
		form1.add(salary, td1);
		salary.setName("basesalary");
		salary.setWidth(133);

		form1.add(new Label("部门由"), td1);
		dep = new BaseComboBoxForm<BaseModelData>("id", "name", "SystemInfo",
				"", true);
		dep.setEnabled(false);
		dep.setWidth(133);
		dep.setName("systemid");
		form1.add(dep, td1);
		form1.add(new Label("改变为 "), td1);
		C_dep = new BaseComboBoxForm<BaseModelData>(
				"id",
				"name",
				"SystemInfo",
				"where name is not null and id is not null and len(id)=(select max(len(id)) from systeminfo)",
				true);
		form1.add(C_dep, td1);
		C_dep.setWidth(133);
		C_dep.setName("systemid");

		C_deppraent = new BaseComboBoxForm<BaseModelData>("id", "name",
				"SystemInfo", "where name is not null and id is not null", true);
		C_deppraent.setName("up_department");
		C_deppraent.setFireChangeEventOnSetValue(true);
		form1.add(C_deppraent, td1);
		C_deppraent.setVisible(false);

		C_num25 = new TextField<String>();
		C_num25.setReadOnly(true);
		C_num25.setName("Identifier");
		C_num25.setFireChangeEventOnSetValue(true);
		form1.add(C_num25, td1);
		C_num25.setVisible(false);

		form1.inited();

		TableLayout t2 = new TableLayout(4);
		form2 = new BaseFormPanel(getStore2());
		form2.setHeaderVisible(false);
		form2.setBodyBorder(false);
		form2.setLayout(t2);
		form2.setPadding(2);

		form2.add(new Label("职级由"), td1);
		employlevel = new TextField<String>();
		employlevel.setEnabled(false);
		employlevel.setName("employlevel");
		employlevel.setWidth(133);
		form2.add(employlevel, td1);
		form2.add(new Label("改变为"), td1);
		form2.add(C_employlevel, td1);
		C_employlevel.setWidth(133);
		C_employlevel.setName("employlevel");

		form2.add(new Label("职位由"), td1);
		employoutertitle = new TextField<String>();
		employoutertitle.setEnabled(false);
		employoutertitle.setWidth(133);
		employoutertitle.setName("employinnertitle");
		form2.add(employoutertitle, td1);
		form2.add(new Label("改变为"), td1);
		form2.add(C_employoutertitle, td1);
		C_employoutertitle.setWidth(133);
		C_employoutertitle.setName("employinnertitle");

		employstatus = new TextField<String>();
		employstatus.setName("employstatus");
		employstatus.setVisible(false);
		C_employstatus.setName("employstatus");
		C_employstatus.setVisible(false);
		form2.add(employstatus, td1);
		form2.add(C_employstatus, td1);
		form2.inited();

		/********************************/
		TableLayout t5 = new TableLayout(2);
		form4 = new BaseFormPanel(getStore3(), false);
		form4.setHeaderVisible(false);
		form4.setBodyBorder(false);
		form4.setLayout(t5);
		form4.setPadding(2);
		form4.add(new Label("默认转正日期:"), td1);

		DateField C_data9 = new DateField();
		C_data9.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-MM-dd"));
		C_data9.setName("entrydate");
		C_data9.setWidth(127);
		C_data9.setReadOnly(true);
		form4.add(C_data9, td1);
		form4.inited();
		/***********************************/
		form3 = new BaseFormPanel(new BaseStore<BusiObject>(), false);
		form3.setBodyBorder(false);
		form3.setPadding(2);
		TableLayout t4 = new TableLayout(8);
		TableData td2 = new TableData();
		td2.setHorizontalAlign(HorizontalAlignment.LEFT);
		td2.setVerticalAlign(VerticalAlignment.MIDDLE);
		td2.setColspan(1);
		td2.setPadding(1);
		form3.setLabelAlign(LabelAlign.TOP);
		form3.setHeaderVisible(false);
		form3.setLayout(t4);
		dimission.setWidth(60);
		resume.setWidth(60);
		form3.add(new Label("离职:　"), td2);
		form3.add(dimission, td2);
		form3.add(resume, td2);
		// form3.add(print);
		form3.add(new Button("打印离职清点", new SelectionListener<ButtonEvent>() {
			public void componentSelected(ButtonEvent ce) {
				final MessageBox box = MessageBox
						.prompt("安全验证", "请再次输入您的登录密码:");
				box.addCallback(new Listener<MessageBoxEvent>() {
					public void handleEvent(MessageBoxEvent be) {
						if (!be.getValue().toString().equals("")) {
							String print_persion_bcode = Env.getEnvbcode();
							if (mainstore.getValue("bcode") == null
									|| mainstore.getValue("bcode") == "") {
								Info.display("提示消息", "请先选择一个员工在进行操作！");
								return;
							}
							String sql = "select password from bcode where bcode='"
									+ print_persion_bcode
									+ "' and password='"
									+ be.getValue().toString() + "'";
							final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
									.create(com.base.myproject.client.tools.GreetingService.class);
							greetingService2.getDataSet(sql,
									new AsyncCallback<DataSet>() {
										@Override
										public void onFailure(Throwable caught) {
											
										}
										@Override
										public void onSuccess(DataSet result) {
											if (result.getRowCount() > 0) {
												String sql = " insert into print_record (print_type,print_persion,print_date,bcode)"
													+ " values ('离职清点表','"+ Env.getEnvname()+ "',getdate(),'lz_persion_bcode')";
												EmployChange_func Func = new EmployChange_func();
												Func.Command_esc(sql);
												Info.display("提示消息","您的打印记录已近存入到数据库！");
												String bcode = mainstore.getValue("bcode").toString();
												Window.open(GWT.getHostPageBaseURL() + "hr_Jsp/printCheckList.jsp?bcode=" + bcode,"_blank", "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
											} else {
												Info.display("提示消息","您输入的密码有误,请重新输入!");
											}
										}
									});

						}
					}
				});
			}
		}), td2);
		btnLeaveInquiry = new Button("离职调查表");
		btnLeaveInquiry.addListener(Events.OnClick, getListener());
		form3.add(btnLeaveInquiry, td2);

		form3.add(new Label("酒店离职原因:"), td2);
		bcLeaveReason.setWidth(127);
		form3.add(bcLeaveReason, td2);

		FieldSet fs_from = new FieldSet();
		fs_from.setHeading("变动条件");
		form.setStyleName("from_padding_top_bottom");
		VerticalPanel vp = new VerticalPanel();
		vp.add(form);

		FieldSet fs_Entry = new FieldSet();
		fs_Entry.setHeading("入职操作");
		HorizontalPanel hp_entry = new HorizontalPanel();
		hp_entry.setHorizontalAlign(HorizontalAlignment.LEFT);
		hp_entry.setVerticalAlign(VerticalAlignment.MIDDLE);
		hp_entry.add(new Label("入职："));
		hp_entry.add(entry);
		fs_Entry.add(hp_entry);
		vp.add(fs_Entry);

		FieldSet fs_opt = new FieldSet();
		fs_opt.setHeading("变动操作");
		HorizontalPanel hp = new HorizontalPanel();
		hp.add(form1);
		hp.add(form2);
		fs_opt.add(hp);
		vp.add(fs_opt);

		FieldSet fs_ZhuanZhen = new FieldSet();
		fs_ZhuanZhen.setHeading("转正操作");
		HorizontalPanel hp2 = new HorizontalPanel();
		hp2.add(getform_zz());
		hp2.add(form4);
		fs_ZhuanZhen.add(hp2);
		vp.add(fs_ZhuanZhen);

		FieldSet fs_LiZhi = new FieldSet();
		fs_LiZhi.setHeading("离职操作");
		fs_LiZhi.add(form3);
		vp.add(fs_LiZhi);

		fs_from.add(form);
		fs_from.add(vp);
		v.add(fs_from);

		save.addListener(Events.OnClick, getListener());
		dimission.addListener(Events.OnClick, getListener());
		entry.addListener(Events.OnClick, getListener());
		resume.addListener(Events.OnClick, getListener());
		C_dep.addListener(Events.Change, getListener());
		C_employlevel.addListener(Events.Change, getListener());
		C_employoutertitle.addListener(Events.Change, getListener());
		salary.addListener(Events.Change, getListener());
		
		C_dep.addListener(Events.Focus, getListener());
		C_employlevel.addListener(Events.Focus, getListener());
		C_employoutertitle.addListener(Events.Focus, getListener());
		salary.addListener(Events.Focus, getListener());
		return v;
	}

	BaseFormPanel getform_zz() {
		BaseFormPanel form = new BaseFormPanel(createStore_ZZ(), false);
		form.setBodyBorder(false);
		form.setPadding(2);
		TableLayout tl = new TableLayout(6);
		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.MIDDLE);
		form.setLayout(tl);
		form.setStyleName("form_css1");
		form.setHeaderVisible(false);

		form.add(new Label("转正/再入职:    "), td);

		checkBox1.setBoxLabel("延续年限");
		checkBox1.setName("whether_continue");
		form.add(checkBox1, td);

		bt1.addListener(Events.OnClick, getListener());
		bt2.addListener(Events.OnClick, getListener());
		bt3.addListener(Events.OnClick, getListener());
		form.add(bt1, td);
		form.add(bt2, td);
		form.add(bt3, td);

		form.inited();

		return form;
	}

	/*****************************/

	BaseStore<BusiObject> jobhis_a_store = null;

	public BaseStore<BusiObject> getJobhis_a_store() {
		if (jobhis_a_store == null) {
			create_job_his_a_Store();
		}
		return jobhis_a_store;
	}

	BaseStore<BusiObject> create_job_his_a_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("startdate");
		type.getField("startdate").setType(Date.class);
		type.addField("enddate");
		type.getField("enddate").setType(Date.class);
		type.addField("companyname");
		type.getField("companyname").setType(String.class);
		type.addField("title");
		type.getField("title").setType(String.class);
		type.addField("salary_rmb");
		type.getField("salary_rmb").setType(Double.class);
		type.addField("leavereason");
		type.getField("leavereason").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_job_his_a");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from bcode_job_his_a where bcode ='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });//
		// 关联主表字段
		jobhis_a_store = new BaseStore<BusiObject>(type, info);
		return jobhis_a_store;
	}

	BaseGridPanel jobhis_a_grid = null;

	BaseGridPanel create_job_his_a_Grid() {
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C3 = new ColumnConfig("startdate", "开始日期", 100);
		DateField dateField3 = new DateField();
		dateField3.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-MM-dd"));
		C3.setEditor(new CellEditor(dateField3));
		C3.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("enddate", "结束日期", 100);
		DateField dateField4 = new DateField();
		dateField4.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-MM-dd"));
		C4.setEditor(new CellEditor(dateField4));
		C4.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C4);
		ColumnConfig C5 = new ColumnConfig("companyname", "公司名称", 200);
		C5.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("title", "职位", 100);
		C6.setEditor(new CellEditor(new TextField<String>()));
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("salary_rmb", "薪金", 100);
		C7.setNumberFormat(NumberFormat.getCurrencyFormat());
		C7.setEditor(new CellEditor(new NumberField()));
		ColumnConfig C8 = new ColumnConfig("salary_rmb", "离职原因", 100);
		C8.setEditor(new CellEditor(new TextField<String>()));

		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		jobhis_a_grid = new BaseGridPanel(create_job_his_a_Store(), cm, true,
				true);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		jobhis_a_grid.getBg().setSelectionModel(cbs);
		jobhis_a_grid.getBg().setWidth(750);
		jobhis_a_grid.getBg().setHeight(400);
		return jobhis_a_grid;
	}

	int sync = 0;
	Listener<BaseEvent> defaultlistener;
	EmployChange_func Func = null;

	public Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}
		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						if (mainstore.getValue(0, "bname") != null) {
							bname = mainstore.getValue(0, "bname").toString();
						}
						
						bcode = mainstore.getValue(0, "bcode").toString();
						if (be.getType() == Events.OnClick) {
							final String remark = C_employeechangeremark
									.getRawValue();
							final String changeTime = changeDate.getRawValue();
							/************* 转正操作 ************/
							if (be.getSource().equals(bt1)) {
								if (!changeTime.equals("")) {
									MessageBox
											.confirm(
													"提示	","您确定要对\t[" + bname + "]\t进行转正操作吗？请详细检查是否延续年限选项<br />转正生效日期为：" + changeTime,
													new Listener<MessageBoxEvent>() {
														public void handleEvent(MessageBoxEvent be) {
															if (be.getButtonClicked().getText().equals(
																			GXT.MESSAGES.messageBox_yes())) {// 选择同意后
																String sql_2 = "select isnull(jobtype,'') as jobtype,isnull(employstatus,'') as employstatus, entrydate from bcode_job "
																		+ "where bcode='"
																		+ bcode
																		+ "'";
																final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
																		.create(com.base.myproject.client.tools.GreetingService.class);
																greetingService2.getDataSet(sql_2,new AsyncCallback<DataSet>() {
																	@Override
																	public void onFailure(
																		Throwable caught) {
																	}

																	@Override
																	public void onSuccess(DataSet result) {
																		if (!result.getValue(0,"employstatus").equals("在职")) {
																			MessageBox.alert(
																					"提示",
																					"不能对非在职的员工进行转正，请你先进行入职操作，谢谢！",
																					null);
																			return;
																		}
																		String entryDate = result.getValue(0, "entrydate");
																		if (comparedDate(entryDate, changeTime)) {
																			MessageBox
																			.alert(
																					"提示",
																					"转正生效日期不能小于等于雇员在职日期，请重新选择生效日期，谢谢！",
																					null);
																			return;
																		}
																		final String jobtype = result.getValue(0,"jobtype");
																		if (!result.getValue(0,"jobtype").equals("")) {
																			if (jobtype.equals("正式工")) {
																				MessageBox.alert("提示","该员工已经是正式工,不需要转正操作！",null);
																					return;
																			} else if (jobtype.equals("暂入职")) {
																				MessageBox.alert("提示","暂入职的员工不能进行转正操作!",null);
																				return;
																			} else {
																				String after = "";
																				if (jobtype.equals("实习生")) {
																					after = "试用工";
																				} else if (jobtype.equals("临时工")) {
																					after = "试用工";
																				} else if (jobtype.equals("试用工")) {
																					after = "正式工";
																				}
																				final String finalAfter = after;
																				String selectSql = "select count(*) num from hr_EmployeeChange where "
																						+ "whether_continue = 0 and after = '"
																						+ after
																						+ "' and bcode = '"
																						+ bcode
																						+ "' and ChangeType = '转正'";
																				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
																						.create(com.base.myproject.client.tools.GreetingService.class);
																				greetingService2
																						.getDataSet(
																								selectSql,
																								new AsyncCallback<DataSet>() {
																									@Override
																									public void onFailure(
																											Throwable caught) {
																									}

																									@Override
																									public void onSuccess(
																											DataSet result) {
																										if (result.getValue(0, "num").equals("0")) {
																											String sql = " insert into hr_EmployeeChange "
																												+ "(bcode,ChangeType,ChangeDate,availableDate,before,after,remark,whether_continue,Notes) "
																												+ "values ('"
																												+ bcode
																												+ "','转正',"
																												+ "'"
																												+ changeTime
																												+ "',getDate(),'"
																												+ jobtype
																												+ "','"
																												+ finalAfter
																												+ "','转正',0,'"
																												+ tfRemark
																														.getRawValue()
																												+ "')";
																											
																											AsyncCallback<CommandSyncReturnObject> back = new AsyncCallback<CommandSyncReturnObject>() {
																												public void onFailure(
																														Throwable caught) {
																													MessageBox.alert("错误",
																															"网络连接失败", null);	
																												}
																												public void onSuccess(
																														CommandSyncReturnObject result) {
																													if (result.isB()) {
																														if (df_date.before(changeDate.getValue())) { // 有效日期大于当前日期
																															Func.opt_Regularization(bcode,finalAfter,checkBox1.getValue(),changeTime,true);
																														} else {// 有效日期小于或等于当前日期
																															Func
																																	.opt_Regularization(
																																			bcode,
																																			finalAfter,
																																			checkBox1
																																					.getValue(),
																																			changeTime,
																																			false);
																														}
																													}
																													else{
																														MessageBox.alert("错误",
																																"错误，错误代码"+result.getMessage(), null);
																														
																													}
																												}
																											};
																											
																											Func.insert_EmployChange(sql, back);
																										} else {
																											MessageBox
																											.alert(
																													"提示",
																													"该员工的已经做过转正操作，不能再进行转正，谢谢！",
																													null);
																											return;
																										}
																									}
																								});
																							}
																						} else {
																							MessageBox
																									.alert(
																											"提示",
																											"该员工的雇佣类型为空,请先选择该员工的雇佣类型，谢谢！",
																											null);
																							return;
																						}
																					}
																				});
															}// 否的时候
														}
													});
								} else {
									MessageBox.alert("提示", "生效日期未填写!请先填写生效日期!",
											null);
									return;
								}
								/********** end 转正操作 **************/
								/********** 取消转正操作 **************/
							} else if (be.getSource().equals(bt2)) {// 回复上次转正操作
								MessageBox.confirm("提示	",
										"您确定要对\t[" + bname + "]\t取消上一次转正操作吗？取消转正后之前的相关转正数据将还原！",
										new Listener<MessageBoxEvent>() {
											public void handleEvent(
													MessageBoxEvent be) {
												if (be
														.getButtonClicked()
														.getText()
														.equals(
																GXT.MESSAGES
																		.messageBox_yes())) {// 选择同意后
													String sql_2 = "select top 1 icode,isnull(before,'') as before,isnull(availableDate,'') as availableDate from  hr_EmployeeChange where changetype='转正' "
															+ "and bcode='"
															+ mainstore
																	.getValue(
																			"bcode")
																	.toString()
															+ "' order by  changedate desc";
													final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
															.create(com.base.myproject.client.tools.GreetingService.class);
													greetingService2.getDataSet(sql_2,new AsyncCallback<DataSet>() {
																		@Override
																		public void onFailure(Throwable caught) {
																		}

																		@Override
																		public void onSuccess(DataSet result) {
																			if (result.getRowCount() > 0) {
																				String sd = result.getValue(0,"availableDate");
																				String before = result.getValue(0, "before");
																				String icode = result.getValue(0,"icode");
																				Func.back_Regularization(bcode,icode,before,df_date,sd);

																			} else {
																				MessageBox.alert("提示","该员工在此之前没有转正记录,不需要撤消转正，谢谢。",null);
																				return;
																			}
																		}
																	});

												}// 否的时候
											}
										});
							}/********* end 取消转正 *********/
							/************ 再入职操作 **********/
							else if (be.getSource().equals(bt3)) {
								if (changeTime.equals("")) {
									MessageBox.alert("提示", "请先填写生效日期后再进行操作！",
											null);
								} else {
									MessageBox.confirm("提示",
											"您确定要对\t[" + bname + "]\t进行“再入职”操作吗？确认操作后相关数据将直接改变<br />再入职生效日期为：" + changeTime,
											new Listener<MessageBoxEvent>() {
												public void handleEvent(
														MessageBoxEvent be) {
													if (be
															.getButtonClicked()
															.getText()
															.equals(
																	GXT.MESSAGES
																			.messageBox_yes())) {// 选择同意后
														String sql1 = "select  count(*) num from hr_EmployeeChange  where ChangeType = '再入职' and whether_continue = 0 and bcode = '"
																+ mainstore
																		.getValue("bcode")
																+ "'";
														final com.base.myproject.client.tools.GreetingServiceAsync greetingService3 = GWT
																.create(com.base.myproject.client.tools.GreetingService.class);
														greetingService3
																.getDataSet(
																		sql1,
																		new AsyncCallback<DataSet>() {
																			@Override
																			public void onFailure(
																					Throwable caught) {
																			}

																			@Override
																			public void onSuccess(
																					DataSet result) {
																				if (result.getValue(0, "num").equals("0")) {
																					String sql = "select  * from bcode_job where employstatus = '离职' and bcode='"
																						+ mainstore
																								.getValue("bcode")
																						+ "'";
																				final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
																						.create(com.base.myproject.client.tools.GreetingService.class);
																				greetingService2
																						.getDataSet(
																								sql,
																								new AsyncCallback<DataSet>() {
																									@Override
																									public void onFailure(
																											Throwable caught) {
																									}

																									@Override
																									public void onSuccess(
																											DataSet result) {
																										if (result
																												.getRowCount() > 0) {
																											final String bcode = mainstore
																													.getValue(
																															"bcode")
																													.toString();
																											String availableDate = result
																													.getValue(
																															0,
																															"Resignationdate");// 离职有效日期
																											if (comparedDate(availableDate, changeTime)) {
																												MessageBox
																												.alert(
																														"提示",
																														"再入职的生效日期不能小于雇员的离职日期，请重新选择生效日期，谢谢",
																														null);
																												return;
																											}
																											
																											String sql = "insert into hr_EmployeeChange "
																													+ "(bcode,ChangeType,ChangeDate,availableDate,before,after,remark,whether_continue,Notes) "
																													+ "values ('"
																													+ bcode
																													+ "','再入职',"
																													+ "'"
																													+ changeTime
																													+ "',getDate(),'离职','在职','再入职',0,'"
																													+ tfRemark
																															.getRawValue()
																													+ "')";
																											Func
																													.insert_EmployChange(sql);// 插入变动记录
																											
																											String sql_material = "select basesalary,(select name from systeminfo where id = systemid) as systemid,employinnertitle,employlevel,employstatus,entrydate from bcode_job,bcode where bcode.bcode = bcode_job.bcode and bcode.bcode = '"
																												+ bcode + "'";   //查询得到该人员的薪金，部门，职级和职位 
																										final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
																												.create(com.base.myproject.client.tools.GreetingService.class);
																										greetingService2
																												.getDataSet(
																														sql_material,
																														new AsyncCallback<DataSet>() {
																															@Override
																															public void onFailure(
																																	Throwable caught) {

																															}

																															@Override
																															public void onSuccess(
																																	DataSet result) {
																																updateEntry(result, bcode, bcode, changeTime, "再入职");
																															}
																														});
																											
																											if (df_date
																													.before(changeDate
																															.getValue())) { // 有效日期大于当前日期
																												Func
																														.Re_Regularization(
																																bcode,
																																checkBox1
																																		.getValue(),
																																changeTime,
																																availableDate,
																																true);
																											} else {// 有效日期小于或等于当前日期
																												Func
																														.Re_Regularization(
																																bcode,
																																checkBox1
																																		.getValue(),
																																changeTime,
																																availableDate,
																																false);
																											}
																										} else {
																											MessageBox
																													.alert(
																															"提示",
																															"请确认该员工是否之前处于离职状态！",
																															null);
																										}
																									}
																								});
																				} else {
																					MessageBox
																					.alert(
																							"提示",
																							"该员工已经做过再入职操作，不能重复操作，谢谢！",
																							null);
																				}
																			}
																		});
													}// 否的时候
												}
											});
								}
							}
							/******************** 离职操作 ****/
							else if (be.getSource().equals(dimission)) {
								if (!changeTime.equals("")) {
									MessageBox.confirm("提示	",
											"您确定要对\t[" + bname + "]\t进行离职操作吗？离职后相关数据将直接改变<br />离职生效日期为：" + changeTime,
											new Listener<MessageBoxEvent>() {
												public void handleEvent(
														MessageBoxEvent be) {
													if (be
															.getButtonClicked()
															.getText()
															.equals(
																	GXT.MESSAGES
																			.messageBox_yes())) {// 选择同意后

														final String date1 = changeTime;
														String sql_2 = "select isnull(employstatus,'') as employstatus, isnull(entrydate,'') as entrydate, (select count(*) from hr_EmployeeChange where bcode=bcode_job.bcode and whether_continue=0 and changetype='离职') as num from bcode_job where bcode='" + mainstore.getValue("bcode") + "'";
														final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
																.create(com.base.myproject.client.tools.GreetingService.class);
														greetingService2
																.getDataSet(
																		sql_2,
																		new AsyncCallback<DataSet>() {
																			@Override
																			public void onFailure(
																					Throwable caught) {

																			}

																			@Override
																			public void onSuccess(
																					DataSet result) {
																				if (result
																						.getValue(
																								0,
																								"num")
																						.equals(
																								"0")) {
																					if (result
																							.getValue(
																									0,
																									"employstatus")
																							.equals(
																									"在职")) {
																						String entryDate = result.getValue(0, "entrydate");
																						final String reason = bcLeaveReason.getRawValue();
																						if (comparedDate(entryDate, date1)) {
																							MessageBox
																							.alert(
																									"提示",
																									"离职生效日期不能小于雇员入职日期，请重新选择生效日期，谢谢！",
																									null);
																							return;
																						}
																						
																						if (reason.equals("")) {
																							MessageBox
																							.alert(
																									"提示",
																									"离职原因不能为空，请重新酒店离职原因，再做离职，谢谢！",
																									null);
																							return;
																						}
																						
																						final String bcode = mainstore
																								.getValue(
																										"bcode")
																								.toString();
																						String sql = "insert into hr_EmployeeChange "
																								+ "(bcode,ChangeType,ChangeDate,availableDate,before,after,remark,whether_continue,Notes) "
																								+ "values ('"
																								+ bcode
																								+ "','离职','"
																								+ date1
																								+ "',getDate(),'"
																								+ result
																										.getValue(
																												0,
																												"employstatus")
																								+ "','离职','离职',0,'"
																								+ tfRemark
																										.getRawValue()
																								+ "')";
																						
																						AsyncCallback<CommandSyncReturnObject> back = new AsyncCallback<CommandSyncReturnObject>() {
																							public void onFailure(
																									Throwable caught) {
																								MessageBox.alert("错误",
																										"网络连接失败", null);	
																							}
																							public void onSuccess(
																									CommandSyncReturnObject result) {
																								if (result.isB()) {
																									if (df_date
																											.before(changeDate
																													.getValue())) { // 有效日期大于当前日期
																										Func
																												.opt_separation(
																														bcode,
																														reason,
																														date1,
																														true);
																									} else {// 有效日期小于或等于当前日期
																										Func
																												.opt_separation(
																														bcode,
																														reason,
																														date1,
																														false);
																									}
																								}
																								else{
																									MessageBox.alert("错误",
																											"错误，错误代码"+result.getMessage(), null);
																									
																								}
																							}
																						};
																						
																						Func.insert_EmployChange(sql, back);
																					} else {
																						MessageBox
																								.alert(
																										"提示",
																										"该员工初始雇用状态为非在职,非在职人员不能进行离职操作！",
																										null);
																					}
																				} else {
																					MessageBox
																							.alert(
																									"提示",
																									"该员工已经离职,不需要操作！",
																									null);
																				}
																			}
																		});
													}// 否的时候
												}
											});
								} else {
									MessageBox.alert("提示", "生效日期未填写!请先填写生效日期!",
											null);
									return;
								} // end 有效时间判断
								
								/******************************************************* end 离职操作 ****************/
								
								
								/** 入职操作
								 * 当用户选择了入职后，查询hr_EmployeeChange表是否已经存在入职记录（还没生效的）或在bcode_job表中雇佣状态为null的和入职日期为null的，
								 * 如果存在，提示人员已经入职。如果说不存在，则查询bcode_job表对于该人员的相关的信息。如果存在相关信息，则将这些相关的信息作为数据insert到
								 * hr_EmployeeChange。根据生效日期，insert到hr_EmployeeChange的字段whether_continue设置不同的值（0或1，0为还没生效，1为已经），
								 * 根据生效日期，如果生效日期小于今天，在最后更新bcode_job表的雇佣状态为在职和入职日期为生效日期，并把hr_EmployeeChange的字段whether_continue设置1（生效），
								 * 如果生效日期大于今天，就将update语句放到hr_update_data表中，进行0点更新
								**/
							} else if (be.getSource().equals(entry)) {
								if (!changeTime.equals("")) {
									MessageBox.confirm("提示	",
											"您确定要对\t[" + bname + "]\t进行入职操作吗？入职后相关数据将直接改变<br />入职生效日期为：" + changeTime,
											new Listener<MessageBoxEvent>() {
												public void handleEvent(
														MessageBoxEvent be) {
													if (be
															.getButtonClicked()
															.getText()
															.equals(
																	GXT.MESSAGES
																			.messageBox_yes())) {// 选择同意后
														final String oldBcode = mainstore
																.getValue(
																		"bcode")
																.toString();  //得到操作的人员的bcode
														final String date1 = changeTime;
														//这条SQL用来判断员工是不是已经入职，但还没生效，不允许重复入职
														String sql_employeeChange = "select count(*) as num from hr_EmployeeChange where ChangeType = '入职' and whether_continue = 0 and bcode = '"
															+ oldBcode + "'";
														
														final com.base.myproject.client.tools.GreetingServiceAsync greetingService3 = GWT
														.create(com.base.myproject.client.tools.GreetingService.class);
												greetingService3
														.getDataSet(
																sql_employeeChange,
																new AsyncCallback<DataSet>() {
																	@Override
																	public void onFailure(
																			Throwable caught) {

																	}

																	@Override
																	public void onSuccess(
																			DataSet result) {
																		if (result.getValue(0, "num").equals("0")) {
																			String sql_material = "select cast(basesalary as int) as basesalary,(select name from systeminfo where id = systemid) as systemid,up_department,hr_firstname_zh,hr_lastname_zh,employinnertitle,employlevel,employstatus,entrydate,jobtype from bcode_job,bcode where bcode.bcode = bcode_job.bcode and bcode.bcode = '"
																				+ oldBcode + "'";   //查询得到该人员的薪金，部门，职级和职位 
																		final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
																				.create(com.base.myproject.client.tools.GreetingService.class);
																		greetingService2
																				.getDataSet(
																						sql_material,
																						new AsyncCallback<DataSet>() {
																							@Override
																							public void onFailure(
																									Throwable caught) {

																							}

																							@Override
																							public void onSuccess(
																									final DataSet result1) {
																								if (result1.getValue(0, "jobtype") == null || result1.getValue(0, "systemid") == null || result1.getValue(0, "up_department") == null 
																										|| result1.getValue(0, "hr_firstname_zh") == null || result1.getValue(0, "hr_lastname_zh") == null ||
																										result1.getValue(0, "employinnertitle") == null || result1.getValue(0, "employlevel") == null ||
																										result1.getValue(0, "jobtype") == null) {
																									MessageBox
																									.alert(
																											"提示",
																											"请填写“雇员”和“雇佣工作”中的必填字段，并保存后再入职，谢谢。",
																											null);
																									return;
																								}
																								
																								//入职状态和入职时间为空的判断，为空才能进行入职操作，不为空的话则提示用户
																								if (result1
																										.getValue(
																												0,
																												"employstatus") == null
																										&& result1
																												.getValue(
																														0,
																														"entrydate") == null) {
																									//在进行入职操作之前，由于要insert到工作记录表中，就得得到正式的新bcode
																									String maxBcodeSql = "select maxBcode from maxBcode";
																									final GreetingServiceAsync greetingService = GWT
																											.create(com.base.myproject.client.tools.GreetingService.class);
																									greetingService.getDataSet(maxBcodeSql, new AsyncCallback<DataSet>() {
																										@Override
																										public void onFailure(Throwable caught) {
																										}

																										@Override
																										public void onSuccess(DataSet result) {
																											String maxBcode = result.getValue(0, "maxBcode");
																											int num_ = Integer.parseInt(maxBcode);
																											num_ += 1;
																											int size = maxBcode.length();
																											
																											switch (size) {
																											case 1 : maxBcode = "000" + String.valueOf(num_); break;
																											case 2 : maxBcode = "00" + String.valueOf(num_); break;
																											case 3: maxBcode = "0" + String.valueOf(num_); break;
																											default : maxBcode = String.valueOf(num_);
																											}
																											
																											updateEntry(result1, oldBcode, maxBcode, date1, "入职"); 
																											boolean isTip = false;  //是否提示，true为提示，false为不提示，主要用于当薪金有值的时候，阿威写的类已经有提示了，避免双重提示
																											
																											List<String> lists = new ArrayList<String>();
																											String updateBcodeJobsql = "";

																											
																											String entrySql = "insert hr_EmployeeChange(bcode,ChangeType,ChangeDate,availableDate,after,remark,whether_continue,Notes) values('"
																												+ oldBcode
																												+ "','入职','"
																												+ date1
																												+ "',getDate(),'在职','入职',0,'" 
																												+ maxBcode
																												+ "')";
																											String maxBcodeSql = "update maxBcode set maxBcode = maxBcode + 1";  //这里还得修改下，修改成在服务器那得到maxBcode的时候就更新MAXBCODE表和MAXBCODE
																											lists.add(maxBcodeSql);
																											lists.add(entrySql);
																											updateBcodeJobsql = "update bcode_job set employstatus = '在职',employno = substring(employno,1,4) + '" + maxBcode + "',bcode = '" + maxBcode + "', entrydate = '"
																													+ date1
																													+ "' where bcode = '"
																													+ oldBcode
																													+ "'";
																											String updateSql = "update hr_EmployeeChange set whether_continue = 1 where whether_continue = 0 and bcode = '" + maxBcode + "' and ChangeType = '入职'";
																											//固定津贴的
																											/*String updateFixedExt = "insert bcode_Allowance(bcode,no_,amount,startdate,enddate)  " + 
																																	"select '" + maxBcode + "',code,amount,'" + date1 + "',ployEnddate from FixedExtPloy,bcode a, bcode_job b where a.bcode = b.bcode  " + 
																																	"and a.bcode = '" + maxBcode + "' and ('" + date1 + "' between ployStartDate and ployEnddate) " + 
																																	"and  ( " + 
																																	"exists  " + 
																																	"(select *  from hr_range_zy_c where sheetcode='FixedExtPloy' and upcode=FixedExtPloy.icode and isset =1 and name = employlevel)  " + 
																																	"or  " + 
																																	"exists  " + 
																																	"(select * from hr_range_jobgroup where sheetcode='FixedExtPloy' and upcode=FixedExtPloy.icode and isset =1 and name = jobgroup)  " + 
																																	"or  " + 
																																	"exists  " + 
																																	"(select * from hr_range_jobproperty where sheetcode='FixedExtPloy' and upcode=FixedExtPloy.icode and isset =1 and name = jobproperty)  " + 
																																	"or  " + 
																																	"exists  " + 
																																	"(select * from hr_range_jobtype where sheetcode='FixedExtPloy' and upcode=FixedExtPloy.icode and isset =1 and name = jobtype)  " + 
																																	"or  " + 
																																	"exists  " + 
																																	"(select * from hr_range_cx where sheetcode='FixedExtPloy' and upcode=FixedExtPloy.icode and isset =1 and name = hr_City_Township)  " + 
																																	"or  " + 
																																	"exists  " + 
																																	"(select * from hr_range_hjq where sheetcode='FixedExtPloy' and upcode=FixedExtPloy.icode and isset =1 and name = hr_Census_area) " + 
																																	")";*/
																													
																											
																											if (df_date
																													.before(changeDate
																															.getValue())) {
																												String sql1 = " insert into hr_update_data (SQLS,update_time,status) values ('"
																														+ updateBcodeJobsql
																																.replaceAll(
																																		"'",
																																		"''")
																														+ "','"
																														+ date1
																														+ "',0)";
																												String sql2 = " insert into hr_update_data (SQLS,update_time,status) values ('"
																														+ updateSql
																																.replaceAll(
																																		"'",
																																		"''")
																														+ "','"
																														+ date1
																														+ "',0)";
																												/*String sql3 = " insert into hr_update_data (SQLS,update_time,status) values ('"
																													+ updateFixedExt
																													.replaceAll(
																															"'",
																															"''")
																													+ "','"
																													+ date1
																													+ "',0)";*/
																												lists
																														.add(sql1);
																												lists.add(sql2);
																												//lists.add(sql3);
																											} else {
																												lists.add(updateBcodeJobsql);
																												lists.add(updateSql);
																												bcode = maxBcode;
																												//lists.add(updateFixedExt);
																											}
																											isEntry = true;
																											command(lists, isTip);
																										}
																									});
																								} else {
																									MessageBox
																											.alert(
																													"提示",
																													"该雇员已经入职了，不能再入职",
																													null);
																								}

																							}
																						});
																		} else {
																			MessageBox
																			.alert(
																					"提示",
																					"该雇员已经进行入职操作了（正式入职的有效日期为今天之后），不能再入职",
																					null);
																		}
																	}
																});
														
													}// 否的时候
												}
											});
								} else {
									MessageBox.alert("提示", "生效日期未填写!请先填写生效日期!",
											null);
									return;
								} // end 有效时间判断
							}
							/********************************************** 8**恢复上次离职操 ****************/
							else if (be.getSource().equals(resume)) { // 回复上次离职操作
								MessageBox.confirm("提示	",
										"您确定要对\t[" + bname + "]\t进行离职回复操作吗？回复后，该员工的相关数据将变为之前在职的数据",
										new Listener<MessageBoxEvent>() {
											public void handleEvent(
													MessageBoxEvent be) {
												if (be
														.getButtonClicked()
														.getText()
														.equals(
																GXT.MESSAGES
																		.messageBox_yes())) {// 选择同意后
													String sql_2 = "select top 1 isnull(before,'') as before,isnull(availableDate,'') as availableDate,icode from  hr_EmployeeChange  where changetype='离职' and  bcode='"
															+ mainstore
																	.getValue("bcode")
															+ "' order by availableDate desc";
													final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
															.create(com.base.myproject.client.tools.GreetingService.class);
													greetingService2
															.getDataSet(
																	sql_2,
																	new AsyncCallback<DataSet>() {
																		@Override
																		public void onFailure(
																				Throwable caught) {
																		}

																		public void onSuccess(
																				DataSet result) {
																			if (result
																					.getRowCount() > 0) {
																				if (!result
																						.getValue(
																								0,
																								"before")
																						.equals(
																								"")
																						&& !result
																								.getValue(
																										0,
																										"availableDate")
																								.equals(
																										"")) {
																					String bcode = mainstore
																							.getValue(
																									"bcode")
																							.toString();
																					String before = result
																							.getValue(
																									0,
																									"before");
																					String availableDate = result
																							.getValue(
																									0,
																									"availableDate");
																					String icode = result
																							.getValue(
																									0,
																									"icode");
																					Func
																							.opt_back_separation(
																									bcode,
																									before,
																									availableDate,
																									icode);
																					// Separation(sql,2,result.getValue(0,
																					// "before"));//2代表回复上一次离职操作
																				} else {
																					MessageBox
																							.alert(
																									"提示",
																									"找不到该员工离职前数据,无法操作,请联系管理员！",
																									null);
																				}
																			} else {
																				MessageBox
																						.alert(
																								"提示",
																								"该员工目前为止并没有离职信息,请先确认！",
																								null);
																			}

																		}
																	});
												}// 否的时候
											}

										});

							} else if (be.getSource().equals(btnLeaveInquiry)) {
								Bcode_LeaveInquiry leaveInquiry = new Bcode_LeaveInquiry();
								leaveInquiry.complete();
								BaseTabPanel.getInstance().addTab("离职调查表",leaveInquiry);
							}
						} else if (be.getType() == Events.Change) {
							final String remark = C_employeechangeremark
									.getRawValue();
							final String changeTime = changeDate.getRawValue();
							/************************************************************ 薪金 *******************************************************************************/
							if (be.getSource().equals(salary)) {
								final Double old_s = Double
										.parseDouble(mainstore
												.getValueBefoEdited(
														mainstore
																.getCurcowindex(),
														"basesalary")
												.toString());
								if (!changeTime.equals("")) {
									if (bcode.length() > 4) {
										MessageBox.alert("提示", "不能对还没入职的员工进行薪金的修改，操作失败", null);
										salary.setRawValue(salary1.getRawValue());
										return;
									}
									MessageBox.confirm("提示	",
											"您确定要修改\t [" + bname + "]\t的“薪金”吗？<br />生效日期为：" + changeTime,
											new Listener<MessageBoxEvent>() {
												public void handleEvent(
														MessageBoxEvent be) {
													if (be.getButtonClicked().getText().equals(GXT.MESSAGES.messageBox_yes())) {// 选择同意后
														String hr_salary_ploy_m_sql = "select top 1 * from hr_salary_ploy_m where ploystartdate < '" + changeTime + "' and (ployenddate > '" + changeTime + "' or ployenddate is null ) order by ploystartdate";
														final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
														greetingService2.getDataSet(hr_salary_ploy_m_sql,new AsyncCallback<DataSet>() {
															@Override
															public void onFailure(Throwable caught) {
															}

															@Override
															public void onSuccess(DataSet result) {
																if (result.getRowCount() > 0) {
																	/*************
																	 * 
																	 * 
																	* 取出工资策略范围内的bcode
																	 ******************/
																	String upcode = result.getValue(0,"icode");
																	final String codename = result.getValue(0,"codename");
																	String sqls = "select bcode from s_range_view where sheetcode='Salary_Ploy' and upcode='"+ upcode + "' order by bcode";
																	final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
																		.create(com.base.myproject.client.tools.GreetingService.class);
																	greetingService.getDataSet(sqls,new AsyncCallback<DataSet>() {

																		@Override
																		public void onFailure(Throwable caught) {
																			
																		}

																		@Override
																		public void onSuccess(DataSet result) {
																			int count = result.getRowCount();
																			boolean isExists = true;
																			for (int i = 0; i < count; i++) {
																				if (bcode.equals(result.getValue(i,"bcode"))) {
																					Double salary_new = salary.getValue().doubleValue();
																					salary1.setValue(salary_new);
																					String sql = "insert into hr_EmployeeChange "
																							+ "(bcode,ChangeType,ChangeDate,availableDate,before,after,remark,whether_continue,Notes) "
																							+ "values ('"
																							+ bcode
																							+ "','薪金',"
																							+ "'"
																							+ changeTime
																							+ "',getDate(),'"
																							+ old_s
																							+ "','"
																							+ salary_new
																							+ "','"
																							+ remark
																							+ "',0,'"
																							+ tfRemark
																							.getRawValue()
																							+ "')";
																					insertSalaryBase(bcode, String.valueOf(salary_new), changeTime);
																					Func.insert_EmployChange(sql);// 插入变动记录
																					if (df_date.before(changeDate.getValue())) { // 有效日期大于当前日期
																						
																						Func.opt_salary(bcode,salary_new,codename,changeTime,true);
																					} else {// 有效日期小于或等于当前日期
																						Func.opt_salary(bcode,salary_new,codename,changeTime,false);
																					}
																				} else {
																						isExists = false;
																				}
																			}
																			if (isExists = false) {
																				MessageBox.alert("提示","您所修改的员工没有在对应的工资策略范围内！",null);
																			}
																		}

																	});
																}
															}
														});
													} else {// 否的时候
														salary.setValue(old_s);
													}
												}
											});
								} else {
									salary.setValue(old_s);
									MessageBox.alert("提示", "生效日期未填写!请先填写生效日期!",
											null);
									return;
								}
							}
							/******************************************************* end 薪金 ********************************************/

							/***************************************************** 部门操作begin *********************************************/
							else if (be.getSource().equals(C_dep)) {
								final String old_f_dep = dep.getRawValue();// 改变前部门名称
								final String f_dep_name = C_dep.getRawValue();// 改变后分部门名称
								final String f_dep_id = C_dep.getValue().get("code");// 改变后分部门id
								// dep.setSimpleValue(f_dep_id);
								if (!changeTime.equals("")) {
									MessageBox.confirm("提示	","您确定要修改\t[" + bname + "]\t的“部门”吗？更换部门将清空生效日期（包括）以后老部门的排班！生效日期为：" + changeTime,
											new Listener<MessageBoxEvent>() {
												public void handleEvent(MessageBoxEvent be) {
													if (be.getButtonClicked().getText().equals(GXT.MESSAGES.messageBox_yes())) {// 选择同意后
														String sql2 = "select (select title from systeminfo where id=" + "'" + f_dep_id + "') as a,(select title from systeminfo where id=" + "(select substring('"
																+ f_dep_id + "',0,(select len('" + f_dep_id + "')-1))))as b," + "((select substring('" + f_dep_id + "',0,(select len('" + f_dep_id + "')-1)))) as c";
														final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
														greetingService2.getDataSet(sql2,new AsyncCallback<DataSet>() {
															@Override
															public void onFailure(
																Throwable caught) {
															}

															@Override
															public void onSuccess(DataSet result) {
																if (result.getRowCount() > 0) {
																	String f_sm = result.getValue(0,"a");
																	String up_sm = result.getValue(0,"b");
																	String up_id = result.getValue(0,"c");

																	String sql = "insert into hr_EmployeeChange (bcode,ChangeType,ChangeDate,availableDate,before,after,remark,whether_continue,Notes)values ('"
																		+ bcode + "','部门','" + changeTime + "',getDate(),'" + old_f_dep + "','" + f_dep_name + "','" + remark+ "',0,'" + tfRemark.getRawValue() + "')";
																	
																	String updateSchedule = "update hr_Attendance_schedule set readOnly = 1, ";
																	
																	int dayField = changeDate.getValue().getDate();
																	for (; dayField <= 31; dayField++) {
																		updateSchedule += "r" + dayField + "=null,";
																	}
																	updateSchedule = updateSchedule.substring(0, updateSchedule.length() - 1) + " where bcode = '" + bcode + "' and convert(varchar(7), ym, 120) = '" + changeDate.getRawValue().substring(0, 7) + "' and depCode = '" + dep.getValue().get("code") + "'";
																	List<String> lists = new ArrayList<String>();
																	lists.add(sql);
																	lists.add(updateSchedule);
																	
																	Func.insert_EmployChange(lists);// 插入变动记录
																	
																	String sql2="select title,(select title from systeminfo where id = substring(a.id,0,5)) as prant from systeminfo a where id = '" + f_dep_name + "'";
															
																	final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
																			.create(com.base.myproject.client.tools.GreetingService.class);
																	greetingService2
																			.getDataSet(
																					sql2,
																					new AsyncCallback<DataSet>() {
																						@Override
																						public void onFailure(
																								Throwable caught) {
																						}

																						@Override
																						public void onSuccess(
																								DataSet result) {
																							String updateSql = "update bcode_job set Identifier = '" + result.getValue(0, "prant") + result.getValue(0, "title") + "', employno = '" 
																							+ result.getValue(0, "prant") + result.getValue(0, "title") + bcode + " where bcode = '" + bcode + "'";
																							
																							Func.insert_EmployChange(updateSql);
																						}
																	});
																	
																	String Identifier = up_sm + f_sm;
																	if (df_date.before(changeDate.getValue())) { // 有效日期大于当前日期
																		Func.opt_department(bcode,f_dep_id,up_id,Identifier,changeTime,true);
																	} else {// 有效日期小于或等于当前日期
																		Func.opt_department(bcode,f_dep_id,up_id,Identifier,changeTime,false);
																	}
																	C_employoutertitle.setFilter("where type='hr_title' and department = '" + f_dep_id + "'");
																	C_employoutertitle.setRawValue("");
																	MessageBox.alert("提示", "员工所属部门已经更改，请更改对应的职位，谢谢", null);
																	dep.setSimpleValue(f_dep_id);
																}
															}
														});// end
													} else {// 否的时候
														C_dep.setSimpleValue(dep.getValue().get("code"));
													}
												}
											});
								} else {
									C_dep.setSimpleValue(dep.getValue().get(
											"code"));
									MessageBox.alert("提示", "生效日期未填写!请先填写生效日期!",
											null);
									return;
								}
							}
							/********************************************************* end 部门操作 *********************************************/
							/*********************************************************** 职级操作begin*************************************8 **********/
							else if (be.getSource().equals(C_employlevel)) {
								final String old_employlevel = employlevel
										.getRawValue();
								final String employlevel = C_employlevel
										.getRawValue();
								if (!changeTime.equals("")) {
									MessageBox
											.confirm(
													"提示	",
													"您确定要修改\t[" + bname + "]\t的“职级”吗？<br />生效日期为：" + changeTime,
													new Listener<MessageBoxEvent>() {
														public void handleEvent(
																MessageBoxEvent be) {
															if (be
																	.getButtonClicked()
																	.getText()
																	.equals(
																			GXT.MESSAGES
																					.messageBox_yes())) {// 选择同意后
																String bcode = mainstore
																		.getValue(
																				"bcode")
																		.toString();
																String sql = "insert into hr_EmployeeChange "
																		+ "(bcode,ChangeType,ChangeDate,availableDate,before,after,remark,whether_continue,Notes) "
																		+ "values ('"
																		+ bcode
																		+ "','职级',"
																		+ "'"
																		+ changeTime
																		+ "',getDate(),'"
																		+ old_employlevel
																		+ "','"
																		+ employlevel
																		+ "','"
																		+ remark
																		+ "',0,'"
																		+ tfRemark
																				.getRawValue()
																		+ "')";
																Func
																		.insert_EmployChange(sql);// 插入变动记录

																if (df_date
																		.before(changeDate
																				.getValue())) { // 有效日期大于当前日期
																	Func
																			.opt_employleve(
																					bcode,
																					employlevel,
																					changeTime,
																					true);
																} else {// 有效日期小于或等于当前日期
																	Func
																			.opt_employleve(
																					bcode,
																					employlevel,
																					changeTime,
																					false);
																}
															} else {// 否的时候
																C_employlevel
																		.setRawValue(old_employlevel);
															}
														}
													});
								} else {
									C_employlevel.setRawValue(old_employlevel);
									MessageBox.alert("提示", "生效日期未填写!请先填写生效日期!",
											null);
									return;
								}
							}/************** end 职级操作 ***************/
							/************** 职位操作 ***************/
							else if (be.getSource().equals(C_employoutertitle)) {
								final String old_employoutertitle = employoutertitle
										.getRawValue();
								final String new_employoutertitle = C_employoutertitle
										.getRawValue();
								if (!changeTime.equals("")) {
									MessageBox
											.confirm(
													"提示	",
													"您确定要修改\t[" + bname + "]\t的“职位”吗？<br />生效日期为：" + changeTime,
													new Listener<MessageBoxEvent>() {
														public void handleEvent(
																MessageBoxEvent be) {
															if (be
																	.getButtonClicked()
																	.getText()
																	.equals(
																			GXT.MESSAGES
																					.messageBox_yes())) {// 选择同意后
																String bcode = mainstore
																		.getValue(
																				"bcode")
																		.toString();
																String sql = "insert into hr_EmployeeChange "
																		+ "(bcode,ChangeType,ChangeDate,availableDate,before,after,remark,whether_continue,Notes) "
																		+ "values ('"
																		+ bcode
																		+ "','职位',"
																		+ "'"
																		+ changeTime
																		+ "',getDate(),'"
																		+ old_employoutertitle
																		+ "','"
																		+ new_employoutertitle
																		+ "','"
																		+ remark
																		+ "',0,'"
																		+ tfRemark
																				.getRawValue()
																		+ "')";
																Func
																		.insert_EmployChange(sql);// 插入变动记录
																if (df_date
																		.before(changeDate
																				.getValue())) { // 有效日期大于当前日期
																	Func
																			.opt_employinnertitle(
																					bcode,
																					new_employoutertitle,
																					changeTime,
																					true);
																} else {// 有效日期小于或等于当前日期
																	Func
																			.opt_employinnertitle(
																					bcode,
																					new_employoutertitle,
																					changeTime,
																					false);
																}
															} else {// 否的时候
																C_employoutertitle
																		.setRawValue(old_employoutertitle);
															}
														}
													});
								} else {
									C_employoutertitle
											.setRawValue(old_employoutertitle);
									MessageBox.alert("提示", "生效日期未填写!请先填写生效日期!",
											null);
									return;
								}
								/************** end 职位操作 ***************/
							}
						} else if (be.getType() == Events.Focus) {
							String remark = C_employeechangeremark
							.getRawValue();
							if (remark.equals("")) {
								MessageBox.alert("提示", "变动原因不能为空，请选择变动原因后再进行变动操作，谢谢", null);
								return;
							}
						}
					}
				} finally {
					sync--;
				}
			}

		};
		return defaultlistener;
	}
	
	private boolean comparedDate(String before, String after) {
		int beforeYear = Integer.parseInt(before.substring(0, 4));
		int afterYear = Integer.parseInt(after.substring(0, 4));
		int beforeMonth = Integer.parseInt(before.substring(5, 7));
		int afterMonth = Integer.parseInt(after.substring(5, 7));
		int beforeDay = Integer.parseInt(before.substring(8, 10));
		int afterDay = Integer.parseInt(after.substring(8, 10));

		if (beforeYear > afterYear) {
			return true;
		} else if (beforeYear < afterYear) {
			return false;
		}
		
		if (beforeMonth > afterMonth) {
			return true;
		} else if (beforeMonth < afterMonth) {
			return false;
		}
		
		if (beforeDay >= afterDay) {
			return true;
		}
		
		return false;
	}
	
	private void insertSalaryBase(final String bcode, final String baseSalary, final String date) {
		//这个是对社保基数的处理的，得到社保策略表中的生效日期为最接近今天的社保策略
		String hr_social_base = "select * from (select top 1* from hr_social_base where Adjustdate <= '" + date + "' order by Adjustdate desc union select * from hr_social_base where Adjustdate is null) as a";
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService3 = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService3
				.getDataSet(
						hr_social_base,
						new AsyncCallback<DataSet>() {
							@Override
							public void onFailure(
									Throwable caught) {
							}

							@Override
							public void onSuccess(
									DataSet result) {
								final List<String> socialBaseList = new ArrayList<String>();
								String isExistsSocialBase = "select * from hr_social_basedetail where bcode = '" + bcode + "' and upcode in (";
								String icode = "";
								
								for (int i=0; i<result.getRowCount(); i++) {
									icode = result.getValue(i, "icode");
									socialBaseList.add(icode);
									isExistsSocialBase += icode + ",";
								}
								
								isExistsSocialBase = isExistsSocialBase.substring(0, isExistsSocialBase.length() - 1) + ")";
								
								final com.base.myproject.client.tools.GreetingServiceAsync greetingService3 = GWT
								.create(com.base.myproject.client.tools.GreetingService.class);
						greetingService3
								.getDataSet(
										isExistsSocialBase,
										new AsyncCallback<DataSet>() {
											@Override
											public void onFailure(
													Throwable caught) {
											}

											@Override
											public void onSuccess(
													DataSet result) {
												String insertSql = "";
												List<String> insertSqlList = new ArrayList<String>();
												
												if (result.getRowCount() != socialBaseList.size()) {
													boolean isExistsUpcode = false;
													//insert新增加的人员的社保基数
													for (String icode : socialBaseList) {
														isExistsUpcode = false;
														for (int i=0; i<result.getRowCount(); i++) {
															if (icode.equals(result.getValue(i, "upcode"))) {
																isExistsUpcode = true;
																break;
															}
														}
														if (isExistsUpcode) continue;
														insertSql = "insert hr_social_basedetail(upcode, bcode, socialbase) values(" + icode + ",'" + bcode + "'," + Double
														.parseDouble(baseSalary) + ")";
														insertSqlList.add(insertSql);
													}
													
													
													//如果页面输入的生效日期大于今天，就进行insert到hr_update_data的操作
													if (df_date
															.before(changeDate
																	.getValue())) {
														for (String sql : insertSqlList) {
															insertSqlList.remove(sql);
															insertSqlList.add(" insert into hr_update_data (SQLS,update_time,status) values ('" + sql.replaceAll("'", "''") + "','" + date + "',0)");
														}
													}
													command(insertSqlList, false);
												}
											}
										});
							}
						});
	}
	
	/**
	 * @param result 查询bcode_job和bcode表返回的结果集
	 * @param code bcode
	 * @param date 生效日期
	 */
	private void updateEntry(DataSet result, final String code, final String maxBcode, final String date, final String operation) {
		final String baseSalary = result.getValue(0, "basesalary");
		String systemId = result.getValue(0, "systemid");
		String title = result.getValue(0, "employinnertitle");
		String employlevel = result.getValue(0, "employlevel");
		String sql = "";
		List<String> lists = new ArrayList<String>();
		
		/*
		 * 4个if条件用于判断选中人员的那些记录有值，再进行insert操作
		 */
		if (baseSalary != null
				&& Double
						.parseDouble(baseSalary) != 0) {
			sql = "insert hr_EmployeeChange(bcode,ChangeType,ChangeDate,availableDate,after,remark,whether_continue,Notes) values('"
					+ code
					+ "','薪金','"
					+ date
					+ "',getDate(),'"
					+ baseSalary
					+ "','" + operation + "',0,'" 
					+ tfRemark
					.getRawValue()
					+ "')";
			lists
					.add(sql);
			
			insertSalaryBase(maxBcode, baseSalary, date);
			
			//这里是对薪金进行比例分配操作，用的阿威做的类EmployChange_func
			String hr_salary_ploy_m_sql = "select top 1 * from hr_salary_ploy_m where ploystartdate < '" + date + "' and (ployenddate > '" + date + "' or ployenddate is null ) order by ploystartdate desc";
			final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
					.create(com.base.myproject.client.tools.GreetingService.class);
			greetingService2
					.getDataSet(
							hr_salary_ploy_m_sql,
							new AsyncCallback<DataSet>() {
								@Override
								public void onFailure(
										Throwable caught) {
								}

								@Override
								public void onSuccess(
										DataSet result) {
									String codename = result
											.getValue(
													0,
													"codename");
									EmployChange_func Func = new EmployChange_func();
									
									if (df_date
											.before(changeDate
													.getValue())) {
										Func
										.opt_salary(
												maxBcode,
												Double
														.parseDouble(baseSalary),
												codename,
												date,
												true);
									} else {
										bcode = maxBcode;
										
										Func
										.opt_salary(
												maxBcode,
												Double
														.parseDouble(baseSalary),
												codename,
												date,
												false);
									}
								}
							});
		}

		if (systemId != null) {
			sql = "insert hr_EmployeeChange(bcode,ChangeType,ChangeDate,availableDate,after,remark,whether_continue,Notes) values('"
					+ code
					+ "','部门','"
					+ date
					+ "',getDate(),'"
					+ systemId
					+ "','" + operation + "',0,'" 
					+ tfRemark
					.getRawValue()
					+ "')";
			lists
					.add(sql);
		}

		if (title != null) {
			sql = "insert hr_EmployeeChange(bcode,ChangeType,ChangeDate,availableDate,after,remark,whether_continue,Notes) values('"
					+ code
					+ "','职位','"
					+ date
					+ "',getDate(),'"
					+ title
					+ "','" + operation + "',0,'" 
					+ tfRemark
					.getRawValue()
					+ "')";
			lists
					.add(sql);
		}

		if (employlevel != null) {
			sql = "insert hr_EmployeeChange(bcode,ChangeType,ChangeDate,availableDate,after,remark,whether_continue,Notes) values('"
					+ code
					+ "','职级','"
					+ date
					+ "',getDate(),'"
					+ employlevel
					+ "','" + operation + "',0,'" 
					+ tfRemark
					.getRawValue()
					+ "')";
			lists
					.add(sql);
		}
		
		command(lists, true);
	}

	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}

	private boolean command(List<String> lists, final boolean tip) {
		CommandSyncsql csql = new CommandSyncsql();// 执行sql命令
		for (String sql : lists) {
			csql.getV().add(sql);
		}
		if (csql.getV().size() <= 0) {
			return false;
		} else {
			CommandSyncContainer list = new CommandSyncContainer();// 可以添加的命令
			list.add(csql);

			GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
			greetingService.SendCommandSync(list,
					new AsyncCallback<CommandSyncReturnObject>() {
						@Override
						public void onFailure(Throwable caught) {
							MessageBox.alert("错误", "网络连接失败", null);
						}

						@Override
						public void onSuccess(CommandSyncReturnObject result) {
							if (result.isB()) {
								if (tip) {
									Info.display("提示信息", "对员工数据操作成功");
								}
								
								if (isEntry == true) {
									main.treeStore.load();
									mainstore.getStoreinfo().setSql("select * from bcode where icode='" + mainstore.getValue("icode") + "'");
									mainstore.reload();
									
									getEmployeeChange(bcode, bname);  //得改用监听者模式，不然会重复刷新
									isEntry = false;
								}
							} else {
								MessageBox.alert("错误", "错误，错误代码"
										+ result.getMessage(), null);

							}
						}
					});
		}
		return true;
	}
}
